877C - Slava and tanks - CodeForces Solution


constructive algorithms *1600

Please click on ads to support us..

Python Code:

import sys 
sys.setrecursionlimit(1000000000)
import math
import heapq
import time 
from collections import deque
from collections import defaultdict
mod = 10**9+7
def solve(n):
    o,e = [],[]

    for i in range(1,n+1):
        if i%2==0:
            e.append(i)
        else:
            o.append(i)
    return e+o+e
    




                
                    
    

    
n = int(input())
         
res2 = solve(n)
print(len(res2))
print(*res2)





C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define umap unordered_map
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define ll long long
#define forn(i, l, r) for (int i = l; i <= r; i++)
#define forn_(i, l, r) for (int i = l; i >= r; i--)
#define debug(a) cout << #a << "=" << a << endl;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
int T;

ll n;
void solve() {
	cin >> n;

	cout << n / 2 * 2 + (n + 1) / 2 << endl;
	for (int i = 2; i <= n; i += 2) cout << i << ' ';
	for (int i = 1; i <= n; i += 2) cout << i << ' ';
	for (int i = 2; i <= n; i += 2) cout << i << ' ';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	T = 1;

	while (T--) solve();
	return 0;
}


Comments

Submit
0 Comments
More Questions

1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant